#include "../../config.h"

#include <glibmm/i18n.h>

#include "../application.h"
#include "../mainwindow.h"
#include "p_dialog.h"

namespace gpyp {
namespace pref {

//========================
// Dialog
void Dialog::on_response(int response_id) {
  if (app_.opts().get_use_config()) app_.conf().save();
  Gtk::Dialog::on_response(response_id);
}

#define INIT_PAGE(NAME, ID, LABEL)                              \
  NAME##_(pagegroup_, app, *this, PREF_PAGE_##ID, #NAME, LABEL)
Dialog::Dialog(Application &app, Gtk::Window &parent) :
  Gtk::Dialog(_("Preferences"), parent),
  app_       (app),
  pagegroup_ (notebook_),
  INIT_PAGE  (general,      GENERAL,      _("General")),
  INIT_PAGE  (network,      NETWORK,      _("Network")),
  INIT_PAGE  (command,      COMMAND,      _("Command")),
  INIT_PAGE  (record,       RECORD,       _("Record")),
  INIT_PAGE  (visual,       VISUAL,       _("Visual")),
  INIT_PAGE  (channellist,  CHANNELLIST,  _("Channel list")),
  INIT_PAGE  (favorite,     FAVORITE,     _("Favorite")),
  INIT_PAGE  (menu,         MENU,         _("Menu")),
  INIT_PAGE  (input,        INPUT,        _("Input")),
  INIT_PAGE  (notification, NOTIFICATION, _("Notification")),
  INIT_PAGE  (migemo,       MIGEMO,       _("Migemo"))
{
  notebook_.set_tab_pos(Gtk::POS_LEFT);
  get_vbox()->pack_start(notebook_);
  get_vbox()->set_spacing(2);
  add_button(Gtk::Stock::CLOSE, Gtk::RESPONSE_CLOSE);
  show_all();
}

//========================
// FavoriteDialog
void FavoriteDialog::on_response(int response_id) {
  if (response_id == Gtk::RESPONSE_APPLY) {
    app_.ypcollection()->rematch_favorite();
    app_.mainwindow()->channellist()->resort();
    app_.mainwindow()->channellist()->refilter();
    app_.mainwindow()->channellist()->queue_draw();
    return;
  }
  Gtk::Dialog::on_response(response_id);
}

FavoriteDialog::FavoriteDialog(Application &app,
                               Gtk::Window &parent) :
  Gtk::Dialog(_("Favorite setting"), parent),
  app_       (app),
  favorite_  (app_, *this)
{
  favorite_.set_border_width(2);
  get_vbox()->pack_start(favorite_);
  show_all();
  //add_button(Gtk::Stock::APPLY, Gtk::RESPONSE_APPLY);
  add_button(Gtk::Stock::CLOSE, Gtk::RESPONSE_CLOSE);
}

//========================
// PlayerDialog
PlayerDialog::PlayerDialog(Application &app, Gtk::Window &parent) :
  Gtk::Dialog(_("Player setting"), parent),
  player_    (app, parent)
{
  player_.set_border_width(2);
  get_vbox()->pack_start(player_);
  resize(640, 480);
  show_all();
  add_button(Gtk::Stock::CLOSE, Gtk::RESPONSE_CLOSE);
}

}/*pref*/
}/*gpyp*/
